#include "head.h"


void* worker(void *arg){
    
    status_t *status = (status_t *)arg;
    while(1){
        
        int net_fd;

        pthread_mutex_lock(&status->lock);
        while(status->queue.size == 0 && status->exitFlag == 0){
            pthread_cond_wait(&status->cond, &status->lock);
        }
        if(status->exitFlag == 1){
            pthread_mutex_unlock(&status->lock);
            printf("pthread exit\n");
            pthread_exit(NULL);
        }
        net_fd = status->queue.head->net_fd;
        deQueue(&status->queue);
        
        pthread_mutex_unlock(&status->lock);

        printf("sendFile before\n");
        sendFile(net_fd);
        printf("sendFile after\n");
        close(net_fd);

    }
    return 0;
}
